<template>
	<view class="home">
		<view class="list">
			<view class="list_meun" v-if="type == 1">
				<u--input
				    placeholder="请输入名称"
				    border="none"
				    v-model="name"
					class="list_input"
				  ></u--input>
			</view>
			<view class="list_meun" v-if="type == 2">
				<u--textarea v-model="dect" placeholder="请输入简介" ></u--textarea>
			</view>
		</view>
		<view class="footer" >
			<text class="footer_btn" @click="submit()">保存</text>
		</view>
	</view>
</template>

<script>
	import {userIndexAPI,userUpdateAPI} from '@/api/user'
	export default {
		data() {
			return {
				type:1,
				name:'',
				dect:'',
			}
		},
		mounted() {
			
		},
		onLoad(options) {
			this.type = options.type
		},
		onShow() {
			this.getData()
		},
		methods:{
			getData(){
				var parems = {
					token:uni.getStorageSync('accessToken'),
					id:uni.getStorageSync('userInfo').id
				}
				userIndexAPI(parems).then(res =>{
					var data = res.data.user
					if(res.code == 1){
						this.name = data.index_name
						this.dect = data.index_text
					}else{
						wx.showToast({
							title:res.msg,
							icon:'none'
						})
					}
				})
			},
			submit(){
				if(this.type == 1){
					var parems = {
						token:uni.getStorageSync('accessToken'),
						index_name:this.name
					}
				}else if(this.type == 2){
					var parems = {
						token:uni.getStorageSync('accessToken'),
						index_text:this.dect
					}
				}
				userUpdateAPI(parems).then(res =>{
					if(res.code == 1){
						this.getData()
						uni.navigateBack({
							delta:1
						})
					}else{
						wx.showToast({
							title:res.msg,
							icon:'none'
						})
					}
				})
			}
		}
		
	}
</script>
<style>
	page{
		background: #f6f6f6;
	}
</style>
<style scoped lang="scss">
	.list{
		background: #fff;
		padding: 0 30rpx;
	}
	.list_meun{
		padding: 20rpx 0;
	}
	.list_input{
		font-size: 28rpx;
		color: #333;
		height: 80rpx;
	}
	.footer{
		display: flex;
		align-items: center;
		justify-content: center;
		width: 100%;
		background: #fff;
		position: fixed;
		bottom: 0;
		padding: 15rpx 0;
		.footer_btn{
			font-size: 28rpx;
			color: #fff;
			background: #3c9cff;
			width: 90%;
			height: 80rpx;
			display: flex;
			align-items: center;
			justify-content: center;
			border-radius: 100rpx;
		}
	}
</style>